/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao.impl;

import dao.ChiTietDonDatHangDAO;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import pojo.ChiTietDonDatHang;

/**
 *
 * @author MongKieu
 */
public class ChiTietDonDatHangDAOImpl extends HibernateDaoSupport implements ChiTietDonDatHangDAO {

    @Override
    public List<ChiTietDonDatHang> listChiTietDonDatHang() {
        return getHibernateTemplate().find("from ChiTietDonDatHang");
    }

    @Override
    public List<ChiTietDonDatHang> listChiTietDonHangBanChayNhat(int soLuongSanPhamMax) {
        String myQuery = "from ChiTietDonDatHang group by  MaSanPham order by sum(SoLuong) desc";
        return getSession().createQuery(myQuery).setFirstResult(0).setMaxResults(soLuongSanPhamMax).list();
    }

    

    @Override
    public List<ChiTietDonDatHang> listChiTietDonDatHangBanChayNhatCoPhanTrang(int viTriBatDau, int soLuongSanPham) {
        String myQuery = "from ChiTietDonDatHang group by  MaSanPham order by sum(SoLuong) desc";
        return getSession().createQuery(myQuery).setFirstResult(viTriBatDau).setMaxResults(soLuongSanPham).list();


    }
}
